//
//  RootViewController.m
//  UI3_UIImageView
//
//  Created by dllo on 15/11/10.
//  Copyright (c) 2015年 dllo. All rights reserved.
//

#import "RootViewController.h"
#import "RootView.h"
#import "SecondViewController.h"

@interface RootViewController ()

@end

@implementation RootViewController

//  RootViewController的初始化方法
//- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//{
//    self = super initWithNibName:nibNameOrNil bundle:nibBundleOrNil
//    if (self) {
//        
//        
//    }
//    return self;
//}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    NSLog(@"将要出现");
}


// 注意, viewDidLoad只在创建加载时调用一次,切换回来时将不在调用
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor whiteColor];
    
//     UIImage - 专门用来管理图片的类, 本身不具备显示功能
//     UIImageView -  专门用来显示图片的视图
//    UIImage *image = [UIImage imageNamed:@"image2.jpg"];
//    UIImageView *imageV = [[UIImageView alloc] initWithImage:image];
//    imageV.frame = self.view.frame;
//    [self.view addSubview:imageV];
//    [imageV release];
    
//    UIImageView *imageV = [[UIImageView alloc] initWithFrame:CGRectMake(30, 30, 300, 500)];
//    imageV.image = [UIImage imageNamed:@"image15.jpg"];
//    [self.view addSubview:imageV];
//    [imageV release];
    
    
    RootView *rootV = [[RootView alloc] initWithFrame:CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
    [self.view addSubview:rootV];
    [rootV release];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(50, 50, 50, 50);
    button.backgroundColor = [UIColor redColor];
    [button addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    
    NSLog(@"bbbbb");
    
    
}

- (void)buttonAction
{

    SecondViewController *secondVC = [[SecondViewController alloc] init];
    
    // 切换界面
    // 参数1, 要切换的界面
    // 参数2, 是否需要动画特效
    // 参数3, block - 切换完成时调用
    [self presentViewController:secondVC animated:YES completion:^{
        
        // 切换完成调用
        NSLog(@"%d", __LINE__);
        
    }];
    
    // presentViewController会引起引用计数增加
    NSLog(@"%ld", secondVC.retainCount);
    // 先执行完此方法(buttonAction), 再去切换界面
    NSLog(@"%d", __LINE__);
    [secondVC release];
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    NSLog(@"接收内存告警");
    
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
